package com.hr.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hr.domain.po.Contract;
import com.hr.domain.query.ContractPageParams;
import com.hr.domain.query.ContractPageResult;
import com.hr.domain.vo.ContractVO;
import com.hr.service.ContractService;
import com.hr.mapper.ContractMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 86150
* @description 针对表【contract(租赁合同表)】的数据库操作Service实现
* @createDate 2025-09-24 08:41:55
*/
@Service
@AllArgsConstructor
public class ContractServiceImpl implements ContractService{

    private final ContractMapper contractMapper;

    /**
     * 获取合同列表
     * @return contractList
     */
    @Override
    public List<ContractVO> getContractList() {
        List<ContractVO> contractList = contractMapper.getContractList();
        if (contractList == null){
            return null;
        }
        return contractList;
    }

    /**
     * 分页获取合同列表
     * @param queryParams
     * @return contractPageResult
     */
    @Override
    public ContractPageResult getContractPageList(ContractPageParams queryParams) {
        //开始分页
        PageHelper.startPage(queryParams.getPageNum(), queryParams.getPageSize());
        //传入分页参数
        List<ContractVO> contractList = contractMapper.getContractPageList(queryParams);
        //将返回值强转为Page<Contract>
        Page<ContractVO> page = (Page<ContractVO>) contractList;
        //返回结果
        return new ContractPageResult(page.getTotal(), page.getResult());
    }

    /**
     * 更新合同状态
     * @param id
     * @param status
     * @return msg
     */
    @Override
    public String updateContractStatus(Long id, Integer status) {
        int row = contractMapper.updateContractStatus(id, status);
        return row > 0 ? "合同状态更新成功" : "合同状态更新失败";
    }

    /**
     * 获取合同详情
     * @param id
     * @return contractDetail
     */
    @Override
    public ContractVO getContractDetail(Long id) {
        return contractMapper.getContractDetail(id);
    }
}




